def solution(n: int, a: list) -> str:
    # https://baike.baidu.com/item/%E8%B4%A8%E5%9B%A0%E6%95%B0/6192269
    # 辅助函数：分解素因子
    def prime_factors(num):
        factors = set()
        d = 2
        while num > 1:
            while num % d == 0:
                factors.add(d)
                num //= d
            d += 1
            if d * d > num:
                if num > 1:
                    factors.add(num)
                break
        return factors

    # 获取所有数的所有素因子
    all_factors = set()
    for num in a:
        all_factors.update(prime_factors(num))
    # 如果素因子的数量不超过数组长度，那么可以实现目标
    if len(all_factors) <= n:
        return "Yes"
    else:
        return "No"


if __name__ == '__main__':
    print(solution(4, [1, 2, 3, 4]) == "Yes")
    print(solution(2, [10, 12]) == "No")
    print(solution(3, [6, 9, 15]) == "Yes")
